import requests
import json

def test_agent():
    print("🧪 测试智能天气Agent...")
    
    # 测试基本连接
    try:
        response = requests.get("http://localhost:7003/")
        print(f"✅ Agent响应状态: {response.status_code}")
    except Exception as e:
        print(f"❌ 连接失败: {e}")
        return
    
    # 测试简单任务
    try:
        url = "http://localhost:7003/a2a/tasks/send"
        payload = {
            "message": {
                "content": {
                    "text": "Hamburg天气查询"
                }
            }
        }
        
        print("📤 发送简单天气查询...")
        response = requests.post(url, json=payload, timeout=10)
        
        if response.status_code == 200:
            result = response.json()
            print("✅ 简单查询成功")
            print("📄 响应预览:")
            response_text = result["artifacts"][0]["parts"][0]["text"]
            print(response_text[:300] + "..." if len(response_text) > 300 else response_text)
        else:
            print(f"❌ 请求失败: {response.status_code}")
            print(f"响应: {response.text}")
            
    except Exception as e:
        print(f"❌ 测试失败: {e}")

if __name__ == "__main__":
    test_agent()
